// 不持久化
// import { configureStore } from "@reduxjs/toolkit";
// // 导入reducer
// import counterReducer from "./features/counter";

// export const store = configureStore({
//   reducer: {
//     counter: counterReducer,
//   },
// });
// --------------------------------------------------------------------------------
// 数据持久化，存入sessionsStorage
import { configureStore, combineReducers } from "@reduxjs/toolkit";
import { persistStore, persistReducer } from "redux-persist";
import sessionStorage from "redux-persist/es/storage/session";
// 导入reducer
import counterReducer from "./features/counter";

// 1. 结合所有reducer
export const rootReducer = combineReducers({
  counter: counterReducer,
});

// 2. 设置持续存在缓存的配置
const persistConfig = {
  key: "root",
  storage: sessionStorage,
  blacklist: [],
};

//3. 合并配置好缓存reducer
const myPersistReducer = persistReducer(persistConfig, rootReducer);

// 4.配置暴露持续的store
export const store = configureStore({
  reducer: myPersistReducer,
  middleware: (getDefaultMiddleware) =>
    getDefaultMiddleware({
      serializableCheck: false,
    }),
});

// 5.暴露持续的store
export const persistor = persistStore(store);
